var direninternet = direninternet || {};

direninternet.getBanner = function(name, reason, host) {
    var banner = document.createElement("div");
    banner.id = "direninternet_wrapper";
    banner.className = "direninternet_wrapper";
	
    banner.innerHTML = 
       "<div id='direninternet_inner' style='margin-left:auto;margin-right:auto;width: 60%;height: auto;padding: 10px;text-align: center;'>" + 
       "  <p style='line-height:110%;color: white;text-align: center;margin:10px 5px 15px 20px;'>" + name + " (" + host + ")" + "</p> " + 
       "  <p style='line-height:110%;color: white;text-align: center;margin:10px 5px 15px 20px;'>" + reason + " </p>" + 
       "  <p style='line-height:110%;color: white;text-align: center;margin:10px 5px 15px 20px;'>" +
       "    <span style='color:red;font-size:2em'>boykotediyoruz</span>" +
       "  </p>" +
       "  <p style='line-height:110%;color: white;text-align: center;margin:10px 5px 15px 20px;'>" +
       "    <a style='color:white' href='https://code.google.com/p/direninternet/'>#direninternet</a></p>" + 
       "</div>";
	document.body.insertBefore(banner, document.body.firstChild);
 
	banner.setAttribute("style", 
	    "display: block;" +
		"color: white;" +
		"font-size: 20px; " +
		"font-family: arial; " +
	    "width: 100%; " +
	    "height: auto; " +
	    "background-color: black; " +
	    "vertical-align: middle; " +
	    "float: left;" +
	    "z-index: 2147483647;"  // Hack hack hack, to stop from this div being covered with random elements.
    );  

	$("#direninternet_wrapper").sticky({topSpacing:0});
};

direninternet.insertBanner = function() {
    var uri = new URI(location.href);
    var domain = uri.domain();
    var domainResource = uri.domain() + uri.resource();
    
    var key = null;
	if (domainResource in direninternet.list) {
      key = domainResource;
	} else if (domain in direninternet.list) {
      key = domain;     
	}
    
    if (!key) {
        return;
    }
    direninternet.getBanner(direninternet.list[key].name, 
                direninternet.list[key].reason,
				key);
};

$(document).ready(direninternet.insertBanner);
